<?php
showtips($touclicklang['tcmsg0013'],'tips1',true,$touclicklang['tipsTitle4']);

if(submitcheck('skinsubmit')) {
	$tct = $_POST['tType'];
	$tcc = $_POST['cType'.$tct];
	$tcs = $_POST['tcskin'.$tct];
	
	if($tct != "" && $tcc != "" && $tcs!= ""){
		$tccStr = "";
		foreach($tcc as $tcv){
			$tccStr .= $tcv.",";
		}
		$tccStr = substr($tccStr, 0, -1);
		
		$data = array(
				"b" => $touclickB,
				"z" => $touclickZ,
				"v" => $touclickV,
				"d" => $touclickD,
				"pf" => $touclickPF,
				'cs' => $touclickCS,
				"op" => "1002",
				"t" => $tct,
				"c" => $tccStr,
				"s" => $tcs
		);
		$resRep = touclick_request("http://api.touclick.com/skinclass.touclick", $data, 80);
		//cpmsg($resRep['content']);
		if($resRep['content'] == "alert"){
			cpmsg("{$touclicklang['alert']}", "", 'error');
		}elseif($resRep['content'] == "alerts"){
			cpmsg("{$touclicklang['alerts']}", "", 'error');
		}elseif($resRep['content'] == "live"){
			cpmsg("{$touclicklang['live']}", "action=plugins&cp=$cp&pmod=activate&operation=$operation&do=$do", 'error');
		}elseif($resRep['content'] == "vip"){
			cpmsg("{$touclicklang['vip']}");
		}elseif($resRep['content'] == "yes"){
			cpmsg("{$touclicklang['yes']}", "action=plugins&cp=$cp&pmod=skin&operation=$operation&do=$do", 'succeed');
		}else{
			cpmsg("{$touclicklang['others']}", "", 'error');
		}
		
	}else{
		cpmsg("{$touclicklang['paraneed']}", "", 'error');
	}
}



$data= array(
		"b" => $touclickB,
		"z" => $touclickZ,
		"v" => $touclickV,
		"d" => $touclickD,
		"op" => '1001',
		"pf" => $touclickPF,
		'cs' => $touclickCS,
); 
$resRep = touclick_request("http://api.touclick.com/skinclass.touclick", $data, 80);
if($resRep['content'] == "alert"){
	cpmsg("{$touclicklang['alert']}", "", 'error');
}elseif($resRep['content'] == "alerts"){
	cpmsg("{$touclicklang['alerts']}", "", 'error');
}elseif($resRep['content'] == "live"){
	cpmsg("{$touclicklang['live']}", "action=plugins&cp=$cp&pmod=activate&operation=$operation&do=$do", 'error');
}elseif($resRep['content'] == "vip"){
	cpmsg("{$touclicklang['vip']}");
}
$report = $tcJSON->decode($resRep['content'], true);

// echo "<pre>";
// print_r($report);
// echo "</pre>";

$tctStr="";
$tccStr="";
$tcsStr="";

$tccArr = explode(',', $report[captcha_type]);
foreach ($report[ttlist] as $k1=> $ttList){
	//
	$tctCheck = ($ttList[Tag]==$report[touclick_type]) ? "checked" : "";
	$tctId = "1001".$k1;
	$tctName = "tType".$k1;
	$tctTagName = base64_decode($ttList[Name]);
	$tctStr .= "<LI class='{$tctCheck}' id='{$tctId}'><INPUT class=radio type=radio value={$ttList[Tag]}  $tctCheck autocomplete='off' name='tType'>&nbsp;{$tctTagName}</LI>";
	
	//
	$tccId = "tcc1001".$k1;
	$tccName = "cType".$ttList[Tag]."[]";
	$tccCheck = ($ttList[Tag]==$report[touclick_type]) ? "style='display:block;'" : "style='display:none;'";
	$tccStr .="<UL {$tccCheck} onmouseover='altStyleTc(this)' id='{$tccId}'>";
	foreach ($ttList[CaptchaTypeList] as $capList){
		$tccCheck = in_array($capList[ID], $tccArr) ? "checked" : "";
		$tccTagName = base64_decode($capList[Name]);
		$tccStr .= "<LI class='{$tccCheck}'><INPUT class=checkbox type=checkbox value='{$capList[ID]}' $tccCheck autocomplete='off' name='{$tccName}'>&nbsp;{$tccTagName}</LI>";
	}
	$tccStr .="</UL>";
	
	//
	$tcsId = "tcs1001".$k1;
	$tcsName = "tcskin".$ttList[Tag];
	$tcsCheck = ($ttList[Tag]==$report[touclick_type]) ? "style='display:block;'" : "style='display:none;'";
	$tcsStr .="<UL {$tcsCheck} onmouseover='altStyleTc(this)' id='{$tcsId}'>";
	foreach ($ttList[SkinTypeList] as $skinList){
		$tcsCheck = ($skinList[Tag]==$report[skin_type]) ? "checked" : "";
		$tcsTagName = base64_decode($skinList[Name]);
		$tcsStr .= "<LI class='{$tcsCheck}'><INPUT class=radio type=radio value='{$skinList[Tag]}' $tcsCheck autocomplete='off' name='{$tcsName}'>&nbsp;{$tcsTagName}</LI>";
	}
	$tcsStr .="</UL>";
	
}

showformheader("plugins&cp=$cp&pmod=skin&operation=$operation&do=$do", "", "skinform", "post");
showtableheader("{$touclicklang['definetypeskin']}", "", "", 2);
echo <<<EOF
<tr><TD class=td27 s="1">{$touclicklang['touclicktype']}</TD></TR>
<tr class=noborder>
	<td class="vtop rowform">
		<UL onmouseover=altStyleTc(this);>
		{$tctStr}
		</ul>
	</td>
</tr>
<tr><TD class=td27 s="1">{$touclicklang['captchatype']}</TD></TR>
<tr class=noborder>
	<td class="vtop rowform">
		{$tccStr}
	</td>
</tr>
<tr><TD class=td27 s="1">{$touclicklang['captchaskin']}</TD></TR>
<tr class=noborder>
	<td class="vtop rowform">
	{$tcsStr}
	</td>
</tr>
<tr><td><input class='btn' type=submit value="{$touclicklang['submit']}" id="skinsubmit" name="skinsubmit"/></td></tr>
EOF;
showtablefooter();
showformfooter();

showtableheader();
echo <<<EOF
<tr id="shiliba" class='hover'>
<td><img id="shil" style="width:680px;height:230px;" src="source/plugin/touclick/image/control/skinpic.png"/></td>
</tr>
EOF;
showtablefooter();
?>
<script type="text/JavaScript">
function altStyleTc(obj, disabled) {
	function altStyleClear(obj) {
		var input,
		lis,
		i;
		lis = obj.parentNode.getElementsByTagName('li');
		for (i = 0; i < lis.length; i++) {
			lis[i].className = '';
		}
	}
	var disabled = !disabled ? 0: disabled;
	if (disabled) {
		return;
	}
	var input,
	lis,
	i,
	cc,
	o;
	cc = 0;
	lis = obj.getElementsByTagName('li');
	var flag=0;
	for (i = 0; i < lis.length; i++) {
		lis[i].onclick = function(e) {
			o = BROWSER.ie ? event.srcElement.tagName: e.target.tagName;
			altKey = BROWSER.ie ? window.event.altKey: e.altKey;
			if (cc) {
				return;
			}
			cc = 1;
			input = this.getElementsByTagName('input')[0];
			if (input.getAttribute('type') == 'checkbox' || input.getAttribute('type') == 'radio') {
				if (input.getAttribute('type') == 'radio') {
					altStyleClear(this);
				}
				if (BROWSER.ie || o != 'INPUT' && input.onclick) {
					input.click();
				}
				if (this.className != 'checked') {
					this.className = 'checked';
					input.checked = true;

					var flag = this.id;
					
					if(!isNaN(flag) && flag !=""){
						
						for(var k1 =0;k1< lis.length; k1++){
							document.getElementById("tcs1001"+k1).style.display ='none';
							document.getElementById("tcc1001"+k1).style.display ='none';
						}
						
						document.getElementById("tcs"+flag).style.display ='block';
						document.getElementById("tcc"+flag).style.display ='block';
					}
				} else { 
					this.className = '';
					input.checked = false;
				}
				if (altKey && input.name.match(/^multinew\[\d+\]/)) {
					miid = input.id.split('|');
					mi = 0;
					while ($(miid[0] + '|' + mi)) {
						$(miid[0] + '|' + mi).checked = input.checked;
						if (input.getAttribute('type') == 'radio') {
							altStyleClear($(miid[0] + '|' + mi).parentNode);
						}
						$(miid[0] + '|' + mi).parentNode.className = input.checked ? 'checked': '';
						mi++;
					}
				}
				
			}
		};
		
		lis[i].onmouseup = function(e) {
			cc = 0;
			
		}
	}
}
</script>
